import { BaseEntity } from '@libs/common/entities';
import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, JoinColumn } from 'typeorm';

import { Member } from '@/dingding/member/entities/member.entity';

export enum OvertimeApplyStatus {
  未申请 = '0',
  待审核 = '1',
  通过 = '2',
  拒绝 = '3',
  取消 = '4',
}

export enum OvertimeApproveStatus {
  通过 = '2',
  拒绝 = '3',
}

export const times = [
  { field_1: '1', field_2: `${4 * 60}分`, time: 4 * 60, timeText: '半天' },
  { field_1: '2', field_2: `${8 * 60}分`, time: 8 * 60, timeText: '一天' },
  { field_1: '3', field_2: `${12 * 60}分`, time: 12 * 60, timeText: '一天半' },
  { field_1: '4', field_2: `${16 * 60}分`, time: 16 * 60, timeText: '二天' },
] as const;

@Entity('crm_node_hr_overtime_apply')
export class OvertimeApply extends BaseEntity {
  @ApiProperty({ description: '钉钉 id' })
  @Column({ comment: '钉钉 id' })
  dingId: string;

  @JoinColumn({ name: 'user' })
  user: Member;

  @ApiProperty({ description: '卡片实例Id' })
  @Column({ comment: '卡片实例Id', unique: true })
  outTrackId: string;

  @ApiProperty({ description: '可用时长/单位分钟' })
  @Column({ comment: '可用时长', default: 0 })
  time: number;

  @ApiProperty({ description: '开始时间' })
  @Column({ comment: '开始时间' })
  startDate: string;

  @ApiProperty({ description: '结束时间' })
  @Column({ comment: '结束时间' })
  endDate: string;

  @ApiProperty({ description: '加班原因' })
  @Column({ comment: '加班原因' })
  description: string;

  @ApiProperty({ description: '状态' })
  @Column({ comment: '状态', default: 0 })
  status: OvertimeApplyStatus;

  @ApiProperty({ description: '审批人' })
  @Column({ comment: '审批人', nullable: true })
  approver?: string;

  @ApiProperty({ description: '审批人dingId' })
  @Column({ comment: '审批人dingId', nullable: true })
  approverDingId?: string;

  @ApiProperty({ description: '审批时间' })
  @Column({ type: 'datetime', comment: '审批时间', nullable: true })
  approveTime?: string;

  @ApiProperty({ description: '钉钉审批实例ID' })
  @Column({ comment: '钉钉审批实例ID', nullable: true })
  instanceId?: string;
}
